﻿Imports System.Windows.Forms

Public Class Dialog1

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        StreamerMatch.tempName = TextBox1.Text
        If Not My.Settings.Playernames.Contains(TextBox1.Text) Then
            My.Settings.Playernames.Add(TextBox1.Text)
            My.Settings.PlayerRaces.Add("#q#" + TextBox1.Text)
        End If

        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As New AutoCompleteStringCollection
        For Each s As String In My.Settings.Playernames
            a.Add(s)
        Next
        TextBox1.AutoCompleteCustomSource = a
        TextBox1.Focus()
    End Sub

    Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
        If e.KeyCode = Keys.Return Then
            OK_Button_Click(Me, Nothing)
        ElseIf e.KeyCode = Keys.Escape Then
            Cancel_Button_Click(Me, Nothing)
        End If
    End Sub
End Class
